﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpMedia;
using SdlDotNet.Graphics;
using SdlDotNet.Core;
using SDLHUDEngine;
using Tao.OpenGl;
using System.Drawing;
using System.Drawing.Imaging;
namespace SharpMedia
{
    public class SDLEngine : Engine
    {
        Renderer renderer;
        Surface screen;
        public SDLEngine(Renderer renderer)
        {
            this.renderer = renderer;

        }

        public void Initialize()
        {
            screen = Video.SetVideoMode(1280, 720, true, true);
            Video.WindowCaption = "test";
            Video.Screen.AlphaBlending = true;


            Events.Quit += new EventHandler<QuitEventArgs>(Quit);
            Events.Tick += new EventHandler<TickEventArgs>(Events_Tick);


            Gl.glViewport(0, 0, 1280, 720);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluOrtho2D(0, 1280, 720, 0);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();
            Gl.glShadeModel(Gl.GL_SMOOTH);
            Gl.glClearColor(0, 0, 0, 1);

            bm = new Bitmap(@"d:\FeLiZk\Pictures\4chan\1201684681818.jpg");
            BitmapData data = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);



        }
        Bitmap bm;
        public void Run()
        {
            Events.Run();
        }


        void Events_Tick(object sender, TickEventArgs e)
        {
            SharpMedia.Update();
            //SharpMedia.Render();
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
            Gl.glLoadIdentity();


            Gl.glBegin(Gl.GL_QUADS);
            // Top Left
            Gl.glVertex3f(0, 0, 0);
            // Top Right
            Gl.glVertex3f(100, 0, 0);
            // Bottom Right
            Gl.glVertex3f(100, 100, 0);
            // Bottom Left
            Gl.glVertex3f(0, 100, 0);
            // Done Drawing The Quad
            Gl.glEnd();

            

            Video.GLSwapBuffers();
        }

        void Quit(object sender, QuitEventArgs e)
        {
            Events.QuitApplication();
        }



        #region Engine Members

        public Lizk.SimpleHUD.SizeS WindowSize
        {
            get
            {
                return new Lizk.SimpleHUD.SizeS(1280, 720);
            }
            set
            {
                
            }
        }

        public Lizk.SimpleHUD.SizeS CurrentSize
        {
            get { return new Lizk.SimpleHUD.SizeS(1280, 720); }
        }

        public Lizk.SimpleHUD.WindowMode Windowed
        {
            get
            {
                return Lizk.SimpleHUD.WindowMode.Windowed;
            }
            set
            {
                
            }
        }

        public Lizk.SimpleHUD.PointS MousePosition
        {
            get { return new Lizk.SimpleHUD.PointS(0, 0); }
        }

        public void Reset()
        {
        }

        public void Wait()
        {
        }

        public void Resume()
        {
        }

        public TimeSpan TimeElapsed
        {
            get { return TimeSpan.Zero; }
        }

        public bool IsCursorHidden
        {
            get { return true; }
        }

        public void Close()
        {
            
        }

        #endregion

        #region Engine Members


        public bool StayOnTop
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        #endregion
    }
}
